-
Notifications
You must be signed in to change notification settings - Fork 136
Support global variable #276
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,11 @@ | |||
use cty::*; | |||
|
|||
// This is where you should define the types shared by the kernel and user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these variables should be declared on the crate level. Since it's the correct compilation unit for both userland and kernelspace, they should at least able to access the typing of what's declared here.
By doing this, we could come up with a proc macro, and/or generic Atomic<T>
that wraps these variables in the userland with safe accessors, and leaves them alone in BPF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a good idea.
I didn't come up with this since I just considered collecting info of global variables in probes by ELF symbol table or BTF info.
Your suggestion shows me alternative designs. Cool.
Thanks,
Hello @rsdy Yesterday, I tried to make use of variables defined in What I hoped to make was looked like this let gvar = loaded.global(unsafe { &GLOBAL_VARIABLE }).expect("error on access gvar"); But I couldn't make it. It is easy to get type info from the reference. If there is only one global variable in the probe code, we can assume what Instead I found a workaround that I am not fully satisfied.. let gvar = loaded
.global::<u64>("GLOBAL_VAR")
.expect("error on accessing gvar"); It looks pretty similar to the conventional I still prefer the first API.. Do you have any idea to implement it? |
Compile errors in FC35 and archlinux are caused by change of kernel v5.16 header. |
Signed-off-by: Junyeong Jeong <[email protected]>
Signed-off-by: Junyeong Jeong <[email protected]>
@rsdy It supports users to access global variables of BPF programs. |
Sorry for ignoring this. I actually read and re-read and re-read it and kept trying to come up with a way to make this API cleaner, but the only thing I can think of was using a macro to get the name with something like paste. Either way, it's kinda hackish, unfortunately. |
I am trying to support global variable in RedBPF.
Currently, users can make use of global variables in their probes since RedBPF
relocates
.data
or.bss
section to bpf map at runtime. (Actuallyrelocating
.bss
isn't working correctly)But I think the userspace API is not convenient enough yet.
This code is an exerpt from the example program of this draft PR.
I think that
loaded.map(".bss")
orloaded.map(".data")
using C structure isnot cool enough to access global variable. It feels like C code. I am used to
C and I like it but RedBPF is Rust library. 🙂
I'd like to see more abstract API that exposes individual global variables to
users.
Any suggestion and idea will be welcomed.
Thanks,